home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / ScreenSavers / Clock screen saver Folder / menu-bar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-01  |  3.6 KB  |  180 lines  |  [TEXT/MPS ]

  1. /*
  2.  * MenuBar.c
  3.  *
  4.  *  This source code is absolutely free.  You may use this code in anything
  5.  *  you write, commercial or otherwise, completely free of obligation.
  6.  *
  7.  *  This code is based on the pascal code written by Earle R. Horton found
  8.  *  in the USENET Macintosh Programmer's Guide Volume I (10/18/90) on page
  9.  *  258.   This version, in addition to having been ported to THINK C, has
  10.  *  been altered so that MBarInit does not have to be explicitly called by
  11.  *  the user; instead, it is called the first time MBarHide is called.
  12.  *
  13.  */
  14.  
  15. #include "screen.h"
  16.  
  17. static void MBarInit( void );
  18. void MBarHide( void );
  19. void MBarRestore( void );
  20.  
  21. static short     saveMBarHeight; /* Copy of low memory global */
  22.                                  /* variable MBarHeight */
  23. static RgnHandle saveGrayRgn;    /* Copy of GrayRgn */
  24. static char      hidden = false; /* true if the menu bar is */
  25.                                  /* currently hidden */
  26. static Rect      MBarRect;       /* Rect enclosing the menu bar */
  27. static char      init = false;   /* true if initialization */
  28.                                  /* has been called */
  29.  
  30.  
  31. /*
  32.  * MBarInit
  33.  *
  34.  *  Set up global variables.
  35.  *
  36.  */
  37.  
  38. static void MBarInit( void )
  39. {
  40.  
  41.     init = true;
  42.     
  43.     saveMBarHeight = *((short *) 0xBAA);
  44.     
  45.     SetRect( &MBarRect,
  46.               qd.screenBits.bounds.left,
  47.               qd.screenBits.bounds.top,
  48.               qd.screenBits.bounds.right,
  49.               qd.screenBits.bounds.top + saveMBarHeight );
  50.  
  51. }
  52.  
  53.  
  54.  
  55. /*
  56.  * MBarHide
  57.  *
  58.  *  Hides the menu bar.  This procedure changes the values of
  59.  *  low memory global variables, so compatibility with future
  60.  *  versions of system software should be considered unreliable.
  61.  *
  62.  */
  63.  
  64. void MBarHide( void )
  65. {
  66.  
  67.     RgnHandle   MBarRgn;
  68.     WindowPeek  theWindow;
  69.  
  70.  
  71.     /* Set up global variables */
  72.  
  73.     if ( ! init ) {
  74.         MBarInit();
  75.     }
  76.  
  77.  
  78.     /* Do nothing if the menu bar is already hidden */
  79.  
  80.     if ( hidden ) {
  81.         return;
  82.     }
  83.  
  84.  
  85.     /* Initialize some variables */
  86.  
  87.     hidden = true;
  88.  
  89.     saveGrayRgn = NewRgn();
  90.     MBarRgn = NewRgn();
  91.  
  92.  
  93.     /* Set the low memory variable MBarHeight to zero */
  94.  
  95.     *((short *) 0xBAA) = 0;
  96.  
  97.  
  98.     /* Save the old GrayRgn */
  99.  
  100.     CopyRgn( GetGrayRgn(), saveGrayRgn );
  101.  
  102.  
  103.     /* Add the area of the menu bar to the GrayRgn */
  104.  
  105.     RectRgn( MBarRgn, &MBarRect );
  106.     UnionRgn( saveGrayRgn, MBarRgn, GetGrayRgn() );
  107.  
  108.  
  109.     /* Update visRgn for any windows with newly exposed areas */
  110.  
  111.     theWindow = (WindowPeek) FrontWindow();
  112.     PaintOne( theWindow, MBarRgn );
  113.     PaintBehind( theWindow, MBarRgn );
  114.     CalcVis( theWindow );
  115.     CalcVisBehind( theWindow, MBarRgn );
  116.  
  117.  
  118.     /* Clean up */
  119.  
  120.     DisposeRgn( MBarRgn );
  121.  
  122. }
  123.  
  124.  
  125.  
  126. /*
  127.  * MBarRestore
  128.  *
  129.  *  Restores the menu bar and the GrayRgn to their former values.
  130.  *  This procedure should always be called when going into the
  131.  *  background under Multifinder.
  132.  *
  133.  */
  134.  
  135. void MBarRestore( void )
  136. {
  137.  
  138.     WindowPeek theWindow;
  139.  
  140.  
  141.     /* Do nothing if the menu bar is not hidden */
  142.     
  143.     if ( ! hidden ) {
  144.         return;
  145.     }
  146.  
  147.     
  148.     hidden = false;
  149.  
  150.  
  151.     /* Restore the GrayRgn to its original value */
  152.  
  153.     CopyRgn( saveGrayRgn, GetGrayRgn() );
  154.  
  155.  
  156.     /* Restore MBarHeight to its original value */
  157.     
  158.     *((short *) 0xBAA) = saveMBarHeight;
  159.  
  160.  
  161.     /* Update visRgn for any windows with newly covered areas */
  162.     
  163.     RectRgn( saveGrayRgn, &MBarRect );
  164.     theWindow = (WindowPeek) FrontWindow();
  165.     CalcVis( theWindow );
  166.     CalcVisBehind( theWindow, saveGrayRgn );
  167.  
  168.  
  169.     /* Dispose of our copy of the GrayRgn */
  170.     
  171.     DisposeRgn( saveGrayRgn );
  172.  
  173.  
  174.     /* Make the menu bar visible */
  175.     
  176.     HiliteMenu( 0 );
  177.     DrawMenuBar();
  178.  
  179. }
  180.